package cn.com.twoke.application.game.mario.game.scene;

import cn.com.twoke.application.game.mario.game.util.NextIdUtils;

import java.util.HashMap;
import java.util.Map;

// 场景管理器
public class SceneManager {
    private Map<String, Scene> scenes = new HashMap<>();

    public Scene createScene(String name, CameraPayload cameraPayload) {
        if (scenes.containsKey(name)) {
            return scenes.get(name);
        }
        Scene scene = new Scene(NextIdUtils.getNextId(() -> Scene.PREFIX),  name);
        scene.setCameraPayload(cameraPayload);
        scenes.put(name, scene);
        return scene;
    }

    public Scene getScene(String name) {
        if (!scenes.containsKey(name)) {
            throw new RuntimeException("场景不存在");
        }
        return scenes.get(name);
    }

    public CameraPayload getSceneCamera(String name) {
        return getScene(name).getCameraPayload();
    }
}
